import QtQuick 1.1
import com.nokia.symbian 1.1
import QtWebKit 1.0
import com.nokia.extras 1.1
import "Script.js" as Script
import "pages"

Page {
    id: mainPage
    function zoomPlus(){
            if(webview.scale <= 1.40)
            {
               webview.scale = webview.scale + 0.10
                pageFlickableContent.anchors.rightMargin = pageFlickableContent.anchors.rightMargin + 10
                Script.zoom_text += 0.10
                moins.enabled = true
    //            text_zoom.text = Math.round( Script.zoom_text * 100 )/100 + "x";
            }
            else
            {
                plus.enabled = false
            }
        }
    function zoomMoins(){
            if(webview.scale >= 1.10)
            {
               webview.scale = webview.scale - 0.10;
                pageFlickableContent.anchors.rightMargin = pageFlickableContent.anchors.rightMargin - 10
                Script.zoom_text -= 0.10
                plus.enabled = true
    //            text_zoom.text = Math.round( Script.zoom_text * 100 )/100 + "x";
            }
            else
            {
                moins.enabled = false
            }
        }
    function loading(){
//        statusBar.loading();
        statusbar.loading();
//        busyindicator.opacity = 1
//        busyindicator.running = true

//        progress.opacity = 1
    }
    function loadingFinish(){
        statusbar.finished();

//        busyindicator.running = false
//        busyindicator.opacity = 0

//        progress.opacity = 0
    }
    tools: ToolBarLayout {
        id: toolBarLayout
        ToolButton {
            flat: true
            iconSource: "toolbar-back"
            onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop()
        }
        ToolButton {
            id: plus
            width: 40
            text: "+"
            anchors.right: zone.left
            anchors.rightMargin: 20
            onClicked: zoomPlus()
        }
        ToolButton {
            id: moins
            width: 40
            text: "-"
            enabled: false
            anchors.left: zone.right
            anchors.leftMargin: 20
            onClicked: zoomMoins()
        }
        ToolButton {
            id: zone
            width: 80
            text: "Zone -"
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: webview.back.trigger()
        }
        ToolButton {
            id: menu_btn
            flat: true

            anchors.right: parent.right
            iconSource: "toolbar-menu"
            onClicked: menu.open()

        }
    }
    Menu{
        id: menu
        MenuLayout{
            MenuItem { text: qsTr("A Propos"); onClicked: aboutDialog.open()}
            MenuItem { text: qsTr("Recharger la carte"); onClicked: { webview.reload.trigger()}}
            MenuItem { text: qsTr("Temps de parcours"); onClicked:{
                    window.pageStack.push(Qt.resolvedUrl("pages/Choix.qml"))
//                    hidenWeb();
                }
            }
            MenuItem { text: qsTr("France"); onClicked:{
                    window.pageStack.push(Qt.resolvedUrl("pages/France.qml"))
                }
            }
        }
    }
    Flickable {
            id: pageFlickableContent
//            width: 640
//            height: 480
            anchors.fill: parent
            contentHeight: webview.height
            contentWidth: webview.width
            flickableDirection: Flickable.AutoFlickDirection


                WebView{
                    id: webview
                    url: "http://www.sytadin.developpement-durable.gouv.fr/opencms/sites/sytadin/sys/raster_fs.jsp.html_1819265885.html"
                    scale: 1
                    preferredWidth: pageFlickableContent.width
                    preferredHeight: pageFlickableContent.height
                    onLoadStarted: loading()
                    onLoadFinished: loadingFinish()
                    onLoadFailed: console.debug("Erreur dans le chargement de la page")
//                    onProgressChanged: progressWeb(webview.progress)
                    Behavior on opacity { NumberAnimation { easing.type: Easing.InQuad; duration: 200 }}

                }
        }    
    ScrollDecorator {
        flickableItem: pageFlickableContent
    }
}
